#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
    vector<int> findAnagrams(string s, string p)
    {
        vector<int> v;
        int count = 0;
        int hash1[26] = { 0 }, hash2[26] = { 0 };
        int m = p.size(), n = s.size();
        for (auto& x : p)
            hash1[x - 'a']++;
        for (int l = 0, r = 0; r < n; r++)
        {
            if (hash2[s[r] - 'a'] < hash1[s[r] - 'a']) count++;
            hash2[s[r] - 'a']++;
            if (r - l + 1 > m)
            {
                if (hash2[s[l] - 'a'] <= hash1[s[l] - 'a']) count--;
                hash2[s[l++] - 'a']--;
            }
            if (m == count) v.emplace_back(l);
        }
        return v;
    }
};